package com.hxh.basic.project.service.impl;

import com.alibaba.fastjson.JSON;
import com.hxh.basic.project.entity.ClubForumInfo;
import com.hxh.basic.project.form.forum.AddForumForm;
import com.hxh.basic.project.mapper.ClubForumInfoMapper;
import com.hxh.basic.project.service.IClubForumInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zouyujie
 * @since 2022-11-09
 */
@Service
public class ClubForumInfoServiceImpl extends ServiceImpl<ClubForumInfoMapper, ClubForumInfo> implements IClubForumInfoService {

    /**
     * 发布帖子
     * @param addForumForm
     * @return
     */
    @Override
    public Boolean saveForumInfo(AddForumForm addForumForm) {
        ClubForumInfo clubForumInfo = addForumForm.buildEntity();
        System.out.println(clubForumInfo);
        List<Map<String,String>> inviteList = addForumForm.getInvite();
        if(inviteList.size()!=0) {
            String invite_json_list = JSON.toJSONString(inviteList);//被邀请人用json方式存储
            clubForumInfo.setInviteList(invite_json_list);
        }else{
            clubForumInfo.setInviteList(null);
        }
        Boolean result = this.save(clubForumInfo);
        return result;
    }
}
